const gulp = require('gulp')
const ts = require('gulp-typescript')
const nodemon = require('gulp-nodemon')

const tsProject = ts.createProject('tsconfig.json')

gulp.task('tsc:p', function () {
  gulp.src('package.json')
    .pipe(gulp.dest('dist'))
  return gulp.src('src/**/*.ts')
    .pipe(tsProject())
    .pipe(gulp.dest('dist/app'))
})

gulp.task('tsc', function () {
  return gulp.src('src/**/*.ts')
    .pipe(tsProject())
    .pipe(gulp.dest('dev'))
})

gulp.task('tsc:w', ['tsc'], function () {
  return gulp.watch('src/**/*.ts', ['tsc'])
})

gulp.task('default', ['tsc:w'], function () {
  nodemon({
    script: 'dev/app',
    env: {'NODE_ENV': 'development'},
    watch: 'dev/**/*.js'
  })
})
